<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item label="当前分数为">{{ actorScore }}分</el-form-item>
      <el-form-item label="分数" prop="actorScore">
        <el-input-number
          v-model="ist"
          :max="100"
          :min="-100"
          @change="handleChange"
        />
      </el-form-item>
      <el-form-item label="修改后为">
        <span>{{ form.actorScore }}</span>
      </el-form-item>
      <el-form-item label="打分原因" prop="scoreReason">
        <el-input v-model.trim="form.scoreReason" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { doadd } from '@/api/table'

  export default {
    name: 'TableEdit',
    data() {
      return {
        ist: 0,
        actorScore: '', //当前分数
        actorScorewo: '', //修改后的分数分数
        form: {
          //打分系统数据
          actorScore: '',
          actInfoId: '', //当前项的id
        },

        rules: {
          scoreReason: [
            { required: true, trigger: 'blur', message: '请输入打分原因' },
          ],
          actorScore: [
            {
              required: true,
              message: '请选择改变后的分数',
              trigger: 'change',
            },
            { pattern: /^(\d+)((?:\.\d+)?)$/, message: '请输入合法数字' },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      handleChange(val) {
        console.log(val)
        let rst = this.actorScore - 0
        console.log(rst)
        let ist = val
        console.log(ist)
        let cc = ist + rst
        this.form.actorScore = cc
        this.show = false
        setTimeout(() => {
          this.show = true
        }, 300)
      },
      showEdit(row) {
        this.actorScore = row.actorScore
        console.log(this.actorScore)
        this.form.actInfoId = row.id
        this.title = '分配分数'
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
        this.ist = ''
      },
      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doadd(this.form)
            console.log(msg)
            this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
